<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>websocket</title>
</head>
<body>

</body>
<script type="text/javascript">
    var socket;


    if(!window.WebSocket){

        window.WebSocket = window.MozWebSocket;
    }

    if(window.WebSocket){
        socket = new WebSocket("ws://127.0.0.1:8000/push/luoyu/992ee2f92ac647c29d92902cc64fc53e");
        socket.onmessage = function(event){
            console.log("接收到消息" + event.data);
        };

        socket.onopen = function(event){
            console.log('打开WebSoket 服务正常，浏览器支持WebSocket!');
        };

        socket.onclose = function(event){
            console.log("WebSocket 关闭");
        };
    }else{
        alert("您的浏览器不支持WebSocket协议！");
    }

    function send(message){
        if(!window.WebSocket){return;}
        if(socket.readyState == WebSocket.OPEN){
            socket.send(message);
        }else{
            alert("WebSocket 连接没有建立成功！");
        }

    }
</script>
</html>